package basic.thread;

public class SaleTicket implements Runnable {

	private   Integer ticket = 100;
	private Object Object1 = new Object();

	@Override
	public   void run() {
		for (int i = 0; i < 1000; i++) {
             synchronized (Object1){
			if (ticket > 0) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
                System.out.println((i + 1) + "、" + Thread.currentThread().getName() + "卖出了第" + ticket-- + "张票");
            }


			}

		}
	}
	

}
